package com.dao;

import com.beans.Memberinfo;
import com.beans.PageInfo;
import com.jdbc.DBUtil;

import java.util.List;

public class MemberDao {

    public int getmemberCount(String sreaName,String startDate,String endDate) {
        String sql="select count(*) from memberinfo where 1=1 ";
        if((!"".equals(startDate))&&startDate!=null){
            sql+=" and registerDate >='"+startDate+" 00:00:00' ";
        }
        if((!"".equals(endDate))&&endDate!=null){
            sql+=" and registerDate <='"+startDate+" 23:59:59' ";
        }if((!"".equals(sreaName))&&sreaName!=null){
            sql+=" and memberNo like '%"+sreaName+"%' ";;
        }
        System.out.println("1:"+sql);
        long i= DBUtil.getScalar(sql);
        return (int)i;
    }

    public static List<Memberinfo> getMemberList(PageInfo page,String sreaName,String startDate,String endDate) {
        String sql="select * from memberinfo where 1=1 ";
        if((!"".equals(startDate))&&startDate!=null){
            sql+=" and registerDate >='"+startDate+" 00:00:00' ";
        }
        if((!"".equals(endDate))&&endDate!=null){
            sql+=" and registerDate <='"+endDate+" 23:59:59' ";
        }if((!"".equals(sreaName))&&sreaName!=null){
            sql+=" and memberNo like '%"+sreaName+"%' ";;
        }
        sql+=" limit ?,?";
        System.out.println("2:"+sql);
        return DBUtil.getList(sql,Memberinfo.class,page.getBeginRow(),page.getPageSize());
    }
    public int del(int id) {
        return DBUtil.update("delete  from memberinfo where id=?",id);
    }
    public Memberinfo getbyid(int id) {
        return DBUtil.getSingleObj("select * from memberinfo where id=?",Memberinfo.class,id);
    }
}
